﻿#ifndef ___PCLIB_S_OS_WIN_DISKINFO___
#define ___PCLIB_S_OS_WIN_DISKINFO___

#include "../s_base.hpp"

/**
*@brief     获取1个内置硬盘的硬盘序列号
*@return    硬盘序列号
*/
/*static CPCResult<std::string> PCGetOneDiskSerialNumber_Win32 (void)
{
    CPCResult<std::string> result;

    for (int drive = 0; drive < 16; drive++)
    {
        HANDLE hPhysicalDriveIOCTL = 0;
        char driveName [256];
        sprintf (driveName, "\\\\.\\PhysicalDrive%d", drive);

        //  Windows NT, Windows 2000, Windows Server 2003, Vista
        hPhysicalDriveIOCTL = CreateFile (driveName,
                                GENERIC_READ | GENERIC_WRITE, 
                                FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, 
							    NULL, OPEN_EXISTING, 0, NULL);
        if (hPhysicalDriveIOCTL == INVALID_HANDLE_VALUE)
        {
            continue;
        }
        CPCAutoObj autoClose([&hPhysicalDriveIOCTL](){CloseHandle (hPhysicalDriveIOCTL);});
        
        GETVERSIONINPARAMS GetVersionParams;
        DWORD cbBytesReturned = 0;

        // Get the version, etc of PhysicalDrive IOCTL
        memset ((void*) & GetVersionParams, 0, sizeof(GetVersionParams));

        if ( ! DeviceIoControl (hPhysicalDriveIOCTL, SMART_GET_VERSION,
                NULL, 
                0,
     			&GetVersionParams, sizeof (GETVERSIONINPARAMS),
				&cbBytesReturned, NULL) )
        {
            continue;
        }
       
		// Print the SMART version
        // PrintVersion (& GetVersionParams);
	    // Allocate the command buffer
		ULONG CommandSize = sizeof(SENDCMDINPARAMS) + IDENTIFY_BUFFER_SIZE;
        PSENDCMDINPARAMS Command = (PSENDCMDINPARAMS) malloc (CommandSize);
        CPCAutoObj autoFree([&Command](){free (Command);});

	    // Retrieve the IDENTIFY data
	    // Prepare the command
        // Returns ID sector for ATA
		Command -> irDriveRegs.bCommandReg = 0xEC;  
		DWORD BytesReturned = 0;
	    if ( ! DeviceIoControl (hPhysicalDriveIOCTL, 
				                SMART_RCV_DRIVE_DATA, Command, sizeof(SENDCMDINPARAMS),
								Command, CommandSize,
								&BytesReturned, NULL) )
        {
            continue;
	    } 
		
        // Print the IDENTIFY data
        DWORD diskdata [256];
        USHORT *pIdSector = (USHORT *) ((PSENDCMDOUTPARAMS) Command) -> bBuffer;

        for (int ijk = 0; ijk < 256; ijk++)
        {
            diskdata [ijk] = pIdSector [ijk];
        }

        char serialNumber [256];
        int position = 0;

        //  each integer has two characters stored in it backwards
        for (int index = 10; index <= 19; index++)
        {
            //  get high byte for 1st character
            serialNumber [position++] = (char) (diskdata [index] / 256);

            //  get low byte for 2nd character
            serialNumber [position++] = (char) (diskdata [index] % 256);
        }

        //  end the string 
        serialNumber[position] = '\0';

        //  cut off the trailing blanks
        for (int index = position - 1; index > 0 && isspace(serialNumber [index]); index--)
            serialNumber [index] = '\0';

        if ( (isalnum (serialNumber [0]) || isalnum (serialNumber [19])))
        {
            return result.SetSucc(serialNumber);
        }
    }
    int lastErrCode = PCGetLastError();
    if(lastErrCode == 0)
    {
        return result.SetFail("not find hardware.");
    }
    return result.SetSystemFail(lastErrCode);
}*/




#endif    //___PCLIB_S_OS_WIN_DISKINFO___
